package com.chun.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 记录方法执行时间的aop类
 */
@Aspect
//@Aspect：切面，描述通知与切入点的关系
@Component
public class LogAspect {
    @Around("@annotation(com.chun.annotation.MyAnno)")
    //通知：advice就是共同逻辑的方法
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //target：通知所应用的对象joinPoint
        //切入前
        long startTime = System.currentTimeMillis();
        //切入
        Object result = joinPoint.proceed();
        //切入后
        long endTime = System.currentTimeMillis();
        long elapsedTime = endTime - startTime;
        System.out.println("执行时间：" + elapsedTime + "毫秒");
        return result;
    }
}
